package cf.huzpsb.bcgod;

import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;

public class LoginCMD extends Command {
    public LoginCMD(String name, String permission, String... aliases) {
        super(name, permission, aliases);
    }

    public void execute(CommandSender sender, String[] args) {
        if (!(sender instanceof ProxiedPlayer)) {
            sender.sendMessage("§c后台不能使用此命令!");
        } else if (!((ProxiedPlayer) sender).getServer().getInfo().getName().equalsIgnoreCase(Main.login)) {
            sender.sendMessage("§c您已经登录!");
        } else if (!Main.passcfg.contains(sender.getName())) {
            sender.sendMessage("§c您尚未注册!");
        } else if (args.length != 1) {
            sender.sendMessage("§c命令参数错误!");
        } else {
            if (!Main.passcfg.getString(sender.getName()).equals(args[0])) {
                sender.sendMessage("§c登录失败:密码错误!");
                return;
            }
            ProxiedPlayer player = (ProxiedPlayer) sender;
            sender.sendMessage("§a登录成功,欢迎回来!");
            player.connect(Main.getInstance().getProxy().getServerInfo(Main.hub));
        }
    }
}
